package com.hb.trade.server.project.sms.controller;


import cn.hutool.core.bean.BeanUtil;
import com.hb.core.pojo.project.sms.dto.SmsSendLogDTO;
import com.hb.core.pojo.project.sms.entity.SmsSendLog;
import com.hb.trade.server.project.sms.service.SmsSendLogService;
import org.fzzn.core.model.msg.Message;
import org.fzzn.core.util.MsgUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuezheng
 * @since 2022-04-20
 */
@RestController
public class SmsSendLogController {

    @Autowired
    private SmsSendLogService smsSendLogService;

    /**
     * 保存短信发送日志
     *
     * @author yuezheng
     * @param smsSendLogDTO
     * @return Message
     * @date 2022/4/20 3:07 PM
     */
    @PostMapping("/smsSendLog/save")
    public Message save(@RequestBody SmsSendLogDTO smsSendLogDTO) {
        boolean flag = this.smsSendLogService.save(smsSendLogDTO);
        return MsgUtil.success(flag);
    }

    /**
     * 批量保存短信发送日志
     *
     * @author yuezheng
     * @param list
     * @return Message
     * @date 2022/4/20 3:07 PM
     */
    @PostMapping("/smsSendLog/saveBatch")
    public Message saveBatch(@RequestBody List<SmsSendLogDTO> list) {

        List<SmsSendLog> logList = list.stream().map(item -> {
            SmsSendLog smsSendLog = new SmsSendLog();
            BeanUtil.copyProperties(item, smsSendLog, true);
            return smsSendLog;
        }).collect(Collectors.toList());
        boolean flag = this.smsSendLogService.saveBatch(logList);

        return MsgUtil.success(flag);
    }

}
